package com.zork.cmdb.webapi.domain.mapper;

import com.zork.cmdb.webapi.domain.dbo.AutoFindResultDO;
import com.zork.cmdb.webapi.domain.dbo.WarehouseInstanceDO;
import com.zork.cmdb.webapi.domain.dto.AutoFindResultDTO;
import com.zork.cmdb.webapi.domain.vo.AutoFindResultVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chenjh
 * @date 2018/6/25
 * @description
 */
@Mapper
public interface AutoFindResultMapper {
    AutoFindResultMapper MAPPER = Mappers.getMapper(AutoFindResultMapper.class);

    default List<AutoFindResultDTO> getDTOList(List<AutoFindResultDO> autoFindResultDOList, List<WarehouseInstanceDO> warehouseInstanceDOList) {
        List<AutoFindResultDTO> resultDTOList = getDTOList(autoFindResultDOList);
        Map<String, WarehouseInstanceDO> warehouseInstanceDOMap = new HashMap<>();
        for (WarehouseInstanceDO warehouseInstanceDO : warehouseInstanceDOList) {
            warehouseInstanceDOMap.put(warehouseInstanceDO.getCiCode(), warehouseInstanceDO);
        }
        for (AutoFindResultDTO autoFindResultDTO : resultDTOList) {
            if (warehouseInstanceDOMap.get(autoFindResultDTO.getCiCode()) == null) {
                continue;
            }
            autoFindResultDTO.setSourceInstanceID(warehouseInstanceDOMap.get(autoFindResultDTO.getCiCode()).getSourceInstanceID());
        }
        return resultDTOList;
    }

    default List<AutoFindResultDTO> getDTOList(List<AutoFindResultDO> autoFindResultDOList, WarehouseInstanceDO warehouseInstanceDO) {
        List<AutoFindResultDTO> resultDTOList = getDTOList(autoFindResultDOList);
        for (AutoFindResultDTO autoFindResultDTO : resultDTOList) {
            autoFindResultDTO.setSourceInstanceID(warehouseInstanceDO.getSourceInstanceID());
        }
        return resultDTOList;
    }
    List<AutoFindResultDTO> getDTOList(List<AutoFindResultDO> autoFindResultDOList);
    List<AutoFindResultVO> getVOList(List<AutoFindResultDTO> autoFindResultDTOList);
}
